예측 기간 : 3월 24일 ~ 4월 23일
# options
options(scipen = 999)
"%ni%" = Negate("%in%")
# library
library(cryptor)
library(data.table)
library(plotly)
library(lubridate)
library(h2o)
h2o.no_progress()
# h2o.show_progress()
# predict_days
predict_days = 30
# get data
# tmp = get_historical_price(fsym="BTT", tsym="KRW", end_time="2019-03-23", unit='hour',limit=1000)
# data = as.data.table(tmp)
data = fread("C:/Users/user/Documents/BITCOIN/input/data.csv")
range(data$time)
## [1] "2013-08-08T06:00:00Z" "2019-03-24T08:00:00Z"
# cut range
data[,date:=as.numeric(gsub("-","",substr(time,1,10)))]
data = data[date>=20181201,]
range(data$time)
## [1] "2018-12-01T00:00:00Z" "2019-03-24T08:00:00Z"
# DM
source("C:/Users/user/Documents/BITCOIN/code/101_BTC200_DM.R")
## >> 101_BTC100_DM done!
# ML
h2o.init(max_mem_size = "12g")
## Connection successful!
##
## R is connected to the H2O cluster:
## H2O cluster uptime: 5 hours 58 minutes
## H2O cluster timezone: Asia/Seoul
## H2O data parsing timezone: UTC
## H2O cluster version: 3.22.1.1
## H2O cluster version age: 2 months and 25 days
## H2O cluster name: H2O_started_from_R_user_jlu559
## H2O cluster total nodes: 1
## H2O cluster total memory: 10.47 GB
## H2O cluster total cores: 4
## H2O cluster allowed cores: 4
## H2O cluster healthy: TRUE
## H2O Connection ip: localhost
## H2O Connection port: 54321
## H2O Connection proxy: NA
## H2O Internal Security: FALSE
## H2O API Extensions: Algos, AutoML, Core V3, Core V4
## R Version: R version 3.5.2 (2018-12-20)
YHAT_list = list()
max_models = 100
nfolds = 5
stopping_rounds = 20
stopping_tolerance = 0.001
source("C:/Users/user/Documents/BITCOIN/code/200_BTC200_ML.R")
## [1] 0
## >> 200_BTC200_ML done!
# 예측값 보정
source("C:/Users/user/Documents/BITCOIN/code/201_BTC200_ML.R")
## [1] 0
## >> 201_BTC200_ML done!
source("C:/Users/user/Documents/BITCOIN/code/202_BTC200_ML.R")
## [1] 0
## >> 202_BTC200_ML done!
source("C:/Users/user/Documents/BITCOIN/code/203_BTC200_ML.R")
## [1] 0
## >> 203_BTC200_ML done!
source("C:/Users/user/Documents/BITCOIN/code/204_BTC200_ML.R")
## [1] 0
## >> 204_BTC200_ML done!
source("C:/Users/user/Documents/BITCOIN/code/205_BTC200_ML.R")
## [1] 0
## >> 205_BTC200_ML done!
source("C:/Users/user/Documents/BITCOIN/code/206_BTC200_ML.R")
## [1] 0
## >> 206_BTC200_ML done!
source("C:/Users/user/Documents/BITCOIN/code/207_BTC200_ML.R")
## [1] 0
## >> 207_BTC200_ML done!
for(i in paste0("daily_avg_After_",7:1,"day")){
tmp = tail(YHAT_list[i][[1]],1)
YHAT[,price:=ifelse(date == tmp$date,tmp$price,price)]
}
# plot
plot_ly() %>%
add_trace(data=Y, x=~date, y=~price, type = 'scatter', mode = 'lines+markers', line = list(color = 'blue', width = 1), name="실제값") %>%
add_trace(data=YHAT, x=~date, y=~price, type = 'scatter', mode = 'lines+markers', line = list(color = 'red', width = 1, dash='dot'), name="예측값") %>%
layout(xaxis=list(fixedrange=T, title="date"),yaxis=list(fixedrange=T, title="price"),autosize = F, width = 900) %>%
config(displayModeBar = F)
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()